#include <iostream>
#include <map>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
bool next(char *&p)
{
	while (p[0]==' ' || p[0]=='\t' || p[0]=='\0') { if (p[0]=='\0') return false; else p++; }
	while ((p[0]!=' ' && p[0]!='\t') || p[0]=='\0') { if (p[0]=='\0') return false; else p++; }
	while (p[0]==' ' || p[0]=='\t' || p[0]=='\0') { if (p[0]=='\0') return false; else p++; }
	return true;
}
int main(int argc, char**argv)
{
    if (argc!=3) return -1;
    freopen(argv[1],"r",stdin);
    FILE* fp = fopen(argv[2],"w");
    
    srand(time(NULL));
    int a_t = rand();
    fprintf(fp, "#ifndef _INS_TAB_%d__\n",a_t);
    fprintf(fp, "#define _INS_TAB_%d__\n\n",a_t);
    char ch[100];
    int id=0;
    bool is_start = false;
    while (gets(ch))
    {
        if (!ch[0]) continue;
        if (!strncmp(ch,"%%%%",2)) { is_start = !is_start; continue; }
        if (!is_start) continue;
        char buf[100],*p = ch;
        sscanf(p,"%s",buf);
        int count = 0 ;
        while (next(p))
           if (p[0]=='[')
           {
               count++;
               int t=strlen(buf);
               buf[t]='_'; buf[t+1]=0;
           }
        else
            break;
        fprintf(fp, "const int INS_%s = %d;\n",buf,id);
        id++;
    }
    return 0;
}
